﻿using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using WitsWebApi.Application.Services;
using WitsWebApi.Entity.Entities;
using WitsWebApi.Entity.EntityParam;
using WitsWebApi.Entity.PageHelper;

namespace WitsWebApi.Controllers
{
    /// <summary>
    /// 用户详情控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class UserDetailController : ControllerBase
    {
        private readonly IAdminDetailService _IAdminDetailService;
        private readonly IMapper _mapper;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="m_IAdminDetailService"></param>
        public UserDetailController(IMapper m_mapper, IAdminDetailService m_IAdminDetailService)
        {
            _mapper = m_mapper;
            _IAdminDetailService = m_IAdminDetailService;
        }

        /// <summary>
        /// 获取用户
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAdminDetail")]
        public async Task<ActionResult<Admin>> GetAdminDetail(string AdminName)
        {
            try
            {
                var result = await _IAdminDetailService.GetAdminDetailByName(AdminName);

                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddAdminDetail")]
        public async Task<ActionResult<bool>> AddAdminDetail(AdminParam adminParam)
        {
            try
            {
                var result = await _IAdminDetailService.AddAdminDetail(adminParam);

                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }

        /// <summary>
        /// 删除指定用户
        /// </summary>
        /// <returns></returns>
        [HttpDelete("DelAdminByAdminID")]
        public async Task<ActionResult<bool>> DelAdminByAdminID(int[] AdminIDs)
        {
            try
            {
                var result = await _IAdminDetailService.DelAdminByAdminID(AdminIDs);

                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }

        /// <summary>
        /// 修改指定用户信息
        /// </summary>
        /// <param name="adminParam"></param>
        /// <returns></returns>
        [HttpPost("UpdateAdminDetail")]
        public async Task<ActionResult<bool>> UpdateAdminDetail(Admin adminParam)
        {
            try
            {
                var result = await _IAdminDetailService.UpdateAdminDetail(adminParam);

                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="adminPageResult"></param>
        /// <returns></returns>
        [HttpPost("AdminPageData")]
        public async Task<ActionResult> AdminPageData(AdminPageResult adminPageResult)
        {
            try
            {
                var result = await _IAdminDetailService.AdminPageData(adminPageResult);

                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }
    }
}
